package com.kangye.exam.service.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kangye.exam.bean.Gonggao;
import com.kangye.exam.dao.GonggaoDao;
import com.kangye.exam.service.GonggaoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(value = "gonggaoService")
public class GonggaoServiceImpl implements GonggaoService {

    @Resource
    private GonggaoDao gonggaoDao;

    /*
     * @Description 按条件 模糊查询 分页
     * @map 集合里面存放了需要查询的id
     * @pageNum 当前页
     * @pageSize 每页条数
     * @Return 返回PageInfo对象  分页插件封装好的对象类型 包含分页和当前bean的所有信息
     * */
    @Override
    public PageInfo<Gonggao> find_limit(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Gonggao> gonggaos = gonggaoDao.selectByParm(map);
        return new PageInfo<>(gonggaos);
    }

    /*
     * @Description 删除一条公告
     * @gid 公告id
     * @Return 受影响条数
     * */
    @Override
    public int delete(Integer gId) {
        Map<String, Object> map = new HashMap<>();
        map.put("gid", gId);
        return gonggaoDao.deleteByPrimaryKey(map);
    }

    /*
     * @Description 插入一条公告
     * @Gonggao 公告class
     * @Return 受影响条数
     * */
    @Override
    public int insert(Gonggao gonggao) {

        return gonggaoDao.insertSelective(gonggao);
    }

    /*
     * @Description 删除一条公告
     * @itembank 公告class
     * @Return 受影响条数
     * */
    @Override
    public Gonggao selectId(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("gid", id);
        return gonggaoDao.selectByPrimaryKey(map);
    }

    /*
     * @Description 修改一条公告
     * @itembank 公告class
     * @Return 受影响条数
     * */
    @Override
    public int update(Gonggao gonggao) {

        return gonggaoDao.updateByPrimaryKeySelective(gonggao);
    }

    @Override
    public List<Gonggao> selectByTime(String currentTime) {
        return gonggaoDao.selectByTime(currentTime);
    }
}
